package top.chj.day19.collection;

import org.junit.Test;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

/**
 * @Auther:小陈的Java
 *迭代器的使用
 */
public class Test2 {
    @Test
    public void test1(){
        Collection<String> cc = new ArrayList<>();
        cc.add("a");
        cc.add("b");
        cc.add("c");
        Iterator<String> iterator = cc.iterator();
        while (iterator.hasNext()){
            System.out.println(iterator.next());
        }
    }
    @Test
    public void test4(){
        Collection cc = new ArrayList();
        cc.add(1);
        cc.add(2);
        cc.add(3);
        Iterator iterator = cc.iterator();
        int i = 0;
        while (iterator.hasNext()){

            System.out.println(iterator.next());
            if(i==0){
                iterator.remove();
            }
            i++;
        }
        System.out.println(cc);

    }
}
